package com.grom.dao;

import java.util.List;

import com.grom.po.Store;
import com.grom.util.IDCreator;
import com.holder.DBContextHolder;
import com.holder.DBUTil;

public class StoreDaoImpl implements StoreDao {

	public List<Store> getAllStore() {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.select(Store.class);
	}

	public Store getStoreById(String id) {
		String sql = "select * from store where id ='" + id + "'";
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		List<Store> resutl = DBUTil.getResult(sql, Store.class);
		return resutl.get(0);
	}

	public void add(Store store) {
		store.setID(IDCreator.getSingleId());
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.save(store);
	}

	public void update(Store store) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.update(store);
	}

	public void delete(Store store) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.delete(store);
	}

	public List<Store> conditionSelect(String sql) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.getResult(sql, Store.class);
	}

}
